from django.db import models
# Create your models here.
class Books(models.Model):
    id = models.CharField(primary_key=True, max_length=20, verbose_name="图书编号")
    name= models.CharField(max_length=20, verbose_name="图书名称")
    status = models.BooleanField(default=False, verbose_name="是否出借", blank=True)


    class Meta:
        db_table = "books"
        verbose_name = "图书表"

    def __str__(self):
        return self.name



class Record(models.Model):
    book = models.ForeignKey("Books", on_delete=models.CASCADE, verbose_name="书籍")
    name = models.CharField(max_length=20, verbose_name="借书人")
    # 设置auto_created，数据创建时，自动设置为当前时间
    # auto_now：当数据任何一个字段发生修改，否自动更新时间
    s_time = models.DateTimeField(auto_created=True, verbose_name="借书时间", blank=True, null=True)
    e_time = models.DateTimeField(auto_created=True, auto_now=True, verbose_name="还书时间", blank=True)
    state = models.BooleanField(default=False, verbose_name="是否归还", blank=True)